const App = getApp();

Page({
  /**
   * 页面的初始数据
   */
  data: {
    userInfo:{
      thumb:"",
      name: "",
      coin: 0,
      gender: 0,
      selfIntro:"",
      email:"",
      nameChange:"0",
      birthday:"11-09",
      group:"1"
    }
  },

  /**
   * 生命周期函数--监听页面加载，页面跳转传参数使用onLoad的options去获取参数
   */
  onLoad(options) {},

  /**
   * 生命周期函数--监听页面显示, 从二级页面返回时onShow会重新调用而onLoad不会
   */
  onShow() {
    let _this = this;
    _this.setData({
      isLogin: App.checkIsLogin()
    });
    if (_this.data.isLogin) {
      // 获取当前用户信息
      _this.getUserDetail();
    }
  },

  /**
   * 获取当前用户信息
   */
  getUserDetail() {
    let _this = this;
    App._get('user_center', {openId: wx.getStorageSync('openId')}, result => {
      _this.setData({
        userInfo:result
      })
    });
  },

  /**
   * 订单导航跳转
   */
  onTargetOrder(e) {
    let _this = this;
    if (!_this.onCheckLogin()) {
      return false;
    }
    let urls = {
      all: '/pages/order/index?type=all',
      payment: '/pages/order/index?type=payment',
      delivery: '/pages/order/index?type=delivery',
      received: '/pages/order/index?type=received'
    };
    // 转跳指定的页面
    wx.navigateTo({
      url: urls[e.currentTarget.dataset.type]
    })
  },
  //点击基础资料跳转
  getBaseInfo(){
    
    let _this = this;  
    let userInfo=_this.data.userInfo;
    console.log(userInfo);
  
    wx.navigateTo({
      url: '../baseUserInfo/base?user='+JSON.stringify(userInfo)
    })    
  },
  getMyLove(){
    console.log("跳转");
    
    wx.navigateTo({
      url: '../mylove/index'
    })  
  },
  getMyWord(){
    wx.navigateTo({
      url: '../myword/index',
    })
  },
  getNotice(){
    wx.navigateTo({
      url: '../help_document/index',
    })
  },
  /**
   * 菜单列表导航跳转
   */
  onTargetMenus(e) {
    let _this = this;
    if (!_this.onCheckLogin()) {
      return false;
    }
    wx.navigateTo({
      url: '/' + e.currentTarget.dataset.url
    })
  },

  /**
   * 跳转到登录页
   */
  onLogin() {
    wx.navigateTo({
      url: '../login/login',
    });
  },

  /**
   * 验证是否已登录
   */
  onCheckLogin() {
    let _this = this;
    if (!_this.data.isLogin) {
      App.showError('很抱歉，您还没有登录');
      return false;
    }
    return true;
  },

})